import java.util.Arrays;
import java.util.Scanner;
 class  PersonSortable implements Comparable<PersonSortable>{
	private String name;
	private int age;
	public PersonSortable(String name,int age){
		this.name=name;
		this.age=age;
	}
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getAge() {
		return age;
	}

	public void setAge(int age) {
		this.age = age;
	}

	public String toString() {
		return name + "-" +age;
	}

	
	@Override
	public int compareTo(PersonSortable o) {
		int x=this.getName().compareTo(o.getName());
		
		return (x!=0?x:(this.getAge()-o.getAge()));
			
	}
	
}

public class Main {

	public static void main(String[] args) {
		Scanner input =new Scanner(System.in);
		int n=input.nextInt();
		PersonSortable[] person=new PersonSortable[n];
		for(int i=0;i<n;i++){
			person[i]=new PersonSortable(input.next(),input.nextInt());
			
		}
		Arrays.sort(person);
		for(int i=0;i<n;i++){
			System.out.println(person[i]);
		}
		System.out.println(Arrays.toString(PersonSortable.class.getInterfaces()));
		
	}

}